<?php


namespace App\Admin\Actions\Tools;


use App\Admin\Actions\BatchAction;
use App\Models\AdminUser;
use App\PatentFee;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;

class PatentFeeEndBatchAction extends BatchAction
{
    protected $selector = '.patent-fee-end-posts';
    public $name = '批量缴费处理';

    public function handle(Collection $collection, Request $request)
    {
        $state = $request->get('state') ? 1 : 0;
        foreach ($collection as $model) {
            if ($model instanceof PatentFee) {
                $model->state = $state;
                $model->save();
            }
        }
        return $this->response()->success('操作成功！')->refresh();
    }

//
//    public function dialog()
//    {
//        $this->confirm('确定转为已处理吗？');
//    }


    public function form()
    {
        $this->radio('state', '处理情况')->options(['待缴费', '已缴费'])->default(-1);
    }


    public function html()
    {
        return $this->aHtml($this->name);
    }

    public function authorize(AdminUser $user, Collection $collection)
    {
        return $user->role_type == 1;
    }

}
